package com.wd.health.model.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.health.R;
import com.wd.health.model.bean.KslbBean;

import java.util.List;

/**
 * @ProjectName:shopmall
 * @Package:com.bawei.myhealth.model.adapter
 * @ClassName:CircleAdapter01
 * @UpdateUser: 裴童童
 * @date: 2020/12/10
 */
public class CircleAdapter01 extends RecyclerView.Adapter<CircleAdapter01.ViewHolder>{
    private List<KslbBean.ResultBean> list;
    private Context context;

    public CircleAdapter01(List<KslbBean.ResultBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(context,R.layout.item_circle01,null));
    }


    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.tv.setText(list.get(position).getDepartmentName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getListener.onClick(position,list.get(position).getId());
                notifyDataSetChanged();
            }
        });
        if (position==getmPosition()){
            holder.tv.setTextColor(Color.BLUE);
        }else {
            //否则的话就全白色初始化背景
            holder.tv.setTextColor(Color.BLACK);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv_circle_rv01);
        }
    }
    //接口回调
    public interface GetListener {
        void onClick(int position, int id);
    }

    private GetListener getListener;

    public void setGetListener(GetListener getListener) {
        this.getListener = getListener;
    }
    private  int mPosition;

    public int getmPosition() {
        return mPosition;
    }

    public void setmPosition(int mPosition) {
        this.mPosition = mPosition;
    }
} 
